<template>
  <Modal v-model="modal" title="当月活动说明">
    <Form :model="form" ref="form">
        <FormItem>
            <Input v-model="form.remark" class="mr" type="textarea" :autosize="{minRows: 3, maxRows: 7}" :maxlength="300" placeholder="本月活动说明"/>
            <WordCount v-model="form.remark" :total="300" />
        </FormItem>
    </Form>
    <div slot="footer">
        <Button @click="modal = false" size="large" type="text">取消</Button>
        <Button :disabled="btnDisabled" @click="onSave" type="primary" size="large">确定</Button>
    </div>
</Modal>
</template>
<script>
export default {
  data() {
    return {
      modal: false,
      btnDisabled: false,
      year: '',
      month: '',
      form: {
        remark: ''
      }
    }
  },
  methods: {
    openModal() {
      this.modal = true
    },
    closeModal() {
      this.modal = false
    },
    getInfo(y, m) {
      this.year = y
      this.month = m
      this.openModal()
    },
    onSave() {
      if (this.btnDisabled) return
      this.btnDisabled = true
      let param = {
        year: this.year,
        month: this.month,
        remark: this.form.remark
      }
      this.$ajaxPost(`/activity/calendar/update_remark`, param).then(data => {
        this.$Notice.success({
          title: `修改成功`
        })
        this.$emit('complete')
        this.closeModal()
        this.btnDisabled = false
      }).catch(() => {
        this.btnDisabled = false
      })
    }
  }
}
</script>